﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace memcached.Tx
{
    /// <summary>
    /// We assume null is not a valid value.
    /// </summary>
    internal sealed class GetOp : ReadOnlyOp
    {
        [System.Diagnostics.DebuggerHidden]
        public GetOp(ICache real, ICache temp, string key)
            : base(real, temp, key)
        {
        }

        public bool Success;

        public override string Name
        {
            [System.Diagnostics.DebuggerHidden]
            get { return "Get:" + Key; }
        }

        public override object Execute()
        {
            // get the current Volatile value, if set in transaction, or the Committed one
            object current = Temp.Get(Key, out Success);// this will always succeed
            if (Success && current != null)
                return current;
            return Store.Get(Key, out Success);
        }
    }
}